package ar.com.agea.util

import javax.naming.Context
import javax.naming.InitialContext
import javax.naming.NameNotFoundException

import org.slf4j.Logger
import org.slf4j.LoggerFactory


class InitialContextUtil {
	
	private static final Logger log = LoggerFactory.getLogger(InitialContextUtil.class)

	static private Context initialContext = null
	
	private InitialContextUtil() { }
	
	
	static public getInstance() {
		
		if ((initialContext) == null) {
			initialContext = new InitialContext()
		}
		return initialContext
		
	}
	
	static public getProperty(key) {

		// Obtain our environment naming context
		Context envCtx = getInstance().lookup("java:comp/env")
		// Look up our data source
		def property = null
		try {
			property = envCtx.lookup(key) as String
		}
		catch(NameNotFoundException e) {
			log.info(e.getMessage())
		}
	}
	
}
